package com.gagakuai.transport.channel;

import com.gagakuai.utils.internal.ObjectUtil;
import com.gagakuai.utils.internal.StringUtil;

/*
 * @description: 对于channelPipeline的默认实现
 * @author: houhong
 * @create: 2024-03-30 11:43
 */
public class DefaultChannelPipeline implements ChannelPipeline {


    /*
    *
    *  依赖注入，当前的pipeline 所属的channel
    *  这样可以互相拿到所属的channel 和pipeline
    */
    private Channel channel;

    /*
     *  头节点
     */
    private static final String HEAD_NAME = generateName0(HeadContext.class);


    private static  final  String TAIL_NAME= generateName0(TailContext.class);


    protected  DefaultChannelPipeline(Channel channel){


        this.channel = ObjectUtil.checkNotNull(channel, "channel");


    }


    private static String generateName0(Class<?> handlerType) {

        return StringUtil.simpleClassName(handlerType) + "#0";
    }



    /*================================构造在pipeline 中的双向链表=====================================*/


    /*
    *
    *  尾handler 的上下文
    */
    public final class TailContext extends AbstractChannelHandlerContext implements ChannelInboundHandler{


        TailContext(DefaultChannelPipeline pipeline) {

            super(pipeline, null, TAIL_NAME, TailContext.class);
            setAddCompleted();
        }



    }

























}
